<!DOCTYPE html>
<html lang="en">
<title>门禁管理-密码列表</title>
<#import "/layout/layout.html" as body />

<@body.page>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="tabs-container">
        <ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">用户门禁密码列表</a></li>
            <li><a data-toggle="tab" href="#tab-2" onclick="coach_list(1);" aria-expanded="false">教练门禁密码列表</a></li>
            <li><a data-toggle="tab" href="#tab-3" onclick="system_user_list(1);" aria-expanded="false">系统用户门禁密码列表</a></li>
        </ul>
        <div class="tab-content">
            <!-- 订单密码 start -->
            <div id="tab-1" class="tab-pane active">
                <div class="panel-body">
                    <div class="wrapper wrapper-content animated fadeInRight">
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="ibox float-e-margins">
                                    <!--<div class="ibox-title">
                                        <h5 class="pull-left">用户门禁密码列表</h5>
                                    </div>-->
                                    <div class="ibox-content" style="border: 0">
                                        <div class="table-responsive">
                                            <form class="form-inline" role="form">
                                                <div class="form-group">
                                                    <label for="userId">用户ID：</label>
                                                    <input class="form-control" type="text" id="userId" name="userId" style="width:100px;"/>
                                                </div>
                                                <div class="form-group">
                                                    <label for="mobile">手机号：</label>
                                                    <input class="form-control" type="text" id="mobile" name="mobile"/>
                                                </div>
                                                <div class="form-group">
                                                    <label for="orderNumber">订单号：</label>
                                                    <input class="form-control" type="text" id="orderNumber" name="orderNumber"/>
                                                </div>
                                                <div class="form-group">
                                                    <label for="storeId">门店：</label>
                                                    <select id="storeId" name="storeId" data-placeholder="请选择门店..." class="form-control chosen-select" tabindex="4">
                                                        <#if storeList??>
                                                            <option value="">请选择门店</option>
                                                            <#list storeList as store>
                                                                <option value="${store.id!}">${store.storeName!}</option>
                                                            </#list>
                                                        </#if>
                                                    </select>
                                                </div>
                                                <button type="button" id="search" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</button>
                                            </form>
                                            <hr>
                                            <table class="table table-hover table-center dataTables-example">
                                                <thead>
                                                <tr>
                                                    <th>用户ID</th>
                                                    <th>用户昵称</th>
                                                    <th>用户手机</th>
                                                    <th>门店名称</th>
                                                    <th>门禁密码</th>
                                                    <th>密码使用计数</th>
                                                    <th>订单编号</th>
                                                    <th>订单类型</th>
                                                    <th>密码开始时间</th>
                                                    <th>密码结束时间</th>
                                                </tr>
                                                </thead>
                                                <tbody id="access_pwd_list">
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                    <div class="ibox-footer overflow">
                                        <h4 class="pull-left">合计：<span id="accessPwdCount">0</span>条用户门禁密码</h4>
                                        <div id="order-page" class="pull-right copot-page"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 订单密码 end -->
            <!-- 教练密码 start-->
            <div id="tab-2" class="tab-pane">
                <div class="panel-body">
                    <div class="wrapper wrapper-content animated fadeInRight">
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="ibox-content" style="border: 0">
                                    <div class="table-responsive">
                                        <form class="form-inline" role="form">
                                            <div class="form-group">
                                                <label for="c_relationId">教练ID：</label>
                                                <input class="form-control" type="text" id="c_relationId" name="relationId" style="width:100px;"/>
                                            </div>
                                            <div class="form-group">
                                                <label for="c_mobile">教练手机：</label>
                                                <input class="form-control" type="text" id="c_mobile" name="mobile"/>
                                            </div>
                                            <div class="form-group">
                                                <label for="c_storeId">门店：</label>
                                                <select id="c_storeId" name="storeId" data-placeholder="请选择门店..." class="form-control chosen-select" tabindex="4">
                                                    <#if storeList??>
                                                        <option value="">请选择门店</option>
                                                        <#list storeList as store>
                                                            <option value="${store.id!}">${store.storeName!}</option>
                                                        </#list>
                                                    </#if>
                                                </select>
                                            </div>
                                            <button type="button" id="c_search" class="btn btn-outline btn-primary">确认</button>
                                        </form>
                                        <hr>
                                        <!-- dataTables-example -->
                                        <table class="table table-hover table-center dataTables-example">
                                            <thead>
                                            <tr>
                                                <th>教练ID</th>
                                                <th>教练昵称</th>
                                                <th>教练手机</th>
                                                <th>门店名称</th>
                                                <th>门禁密码</th>
                                                <th>密码使用计数</th>
                                                <th>密码开始时间</th>
                                                <th>密码结束时间</th>
                                            </tr>
                                            </thead>
                                            <!-- 页面加载的数据  -->
                                            <tbody id="c_access_pwd_list">
                                            </tbody>

                                        </table>
                                    </div>
                                </div>
                                <div class="ibox-footer overflow">
                                    <h4 class="pull-left">合计：<span id="coach_access_pwd_count">0</span>条教练门禁密码</h4>
                                    <div id="coach-page" class="pull-right copot-page"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 教练密码 end -->
            <!-- 系统用户密码 start-->
            <div id="tab-3" class="tab-pane">
                <div class="panel-body">
                    <div class="wrapper wrapper-content animated fadeInRight">
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="ibox-content" style="border: 0">
                                    <div class="table-responsive">
                                        <form class="form-inline" role="form">
                                            <div class="form-group">
                                                <label for="s_relationId">系统用户ID：</label>
                                                <input class="form-control" type="text" id="s_relationId" name="relationId" style="width:100px;"/>
                                            </div>
                                            <div class="form-group">
                                                <label for="s_mobile">系统用户手机：</label>
                                                <input class="form-control" type="text" id="s_mobile" name="mobile"/>
                                            </div>
                                            <div class="form-group">
                                                <label for="s_storeId">门店：</label>
                                                <select id="s_storeId" name="storeId" data-placeholder="请选择门店..." class="form-control chosen-select" tabindex="4">
                                                    <#if storeList??>
                                                        <option value="">请选择门店</option>
                                                        <#list storeList as store>
                                                            <option value="${store.id!}">${store.storeName!}</option>
                                                        </#list>
                                                    </#if>
                                                </select>
                                            </div>
                                            <button type="button" id="s_search" class="btn btn-outline btn-primary">确认</button>
                                        </form>
                                        <hr>
                                        <!-- dataTables-example -->
                                        <table class="table table-hover table-center dataTables-example">
                                            <thead>
                                            <tr>
                                                <th>系统用户ID</th>
                                                <th>系统用户昵称</th>
                                                <th>系统用户手机</th>
                                                <th>门店名称</th>
                                                <th>门禁密码</th>
                                                <th>密码使用计数</th>
                                                <th>密码开始时间</th>
                                                <th>密码结束时间</th>
                                            </tr>
                                            </thead>
                                            <!-- 页面加载的数据  -->
                                            <tbody id="s_access_pwd_list">
                                            </tbody>

                                        </table>
                                    </div>
                                </div>
                                <div class="ibox-footer overflow">
                                    <h4 class="pull-left">合计：<span id="system_access_pwd_count">0</span>条系统用户门禁密码</h4>
                                    <div id="system-page" class="pull-right copot-page"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 系统用户密码 end -->
        </div>
    </div>
</div>

<script src="${baseUrl}js/main.js"></script>
<script>
    $(document).ready(function () {

        //初始化日期格式化方法
        Date.prototype.pattern = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
                "H+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            var week = {
                "0": "/u65e5",
                "1": "/u4e00",
                "2": "/u4e8c",
                "3": "/u4e09",
                "4": "/u56db",
                "5": "/u4e94",
                "6": "/u516d"
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            if (/(E+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            var str = fmt.lastIndexOf("N");
            if (str != -1) {
                return "";
            }

            return fmt;
        }

        access_pwd_list(1);

        $("#search").click(function () {
            access_pwd_list(1);
        });

        $("#c_search").click(function () {
            coach_list(1)
        });

        $("#s_search").click(function () {
            system_user_list(1)
        });

    });


    function access_pwd_list(currentIndex) {
        debugger
        $("#access_pwd_list").empty();
        var userId = $("#userId").val().trim();
        var mobile = $("#mobile").val().trim();
        var orderNumber = $("#orderNumber").val().trim();
        var storeId = $("#storeId").val().trim();

        $.ajax({
            url: "${baseUrl}system/accessPwd/access_pwd_list",
            data: {
                pageIndex: currentIndex,
                pageSize: 10,
                userId: userId,
                mobile: mobile,
                orderNumber: orderNumber,
                storeId: storeId,
                relationType:0
            },
            type: "POST",
            success: function (result) {
                var html = "";
                //分页
                new Page({
                    parent: $("#order-page"),
                    nowPage: currentIndex,
                    pageSize: 10,
                    totalCount: result.accessPwdCount,
                    setting: {
                        defaultPage: 5,//默认显示可点击分页的个数
                        firstPageText: "首页",
                        prevPageText: "上一页",
                        nextPageText: "下一页",
                        lastPageText: "尾页"
                    },
                    callback: function (nowPage, totalPage) {
                        access_pwd_list(nowPage);
                    }
                });

                $("#accessPwdCount").text(result.accessPwdCount);

                var orderType = "";
                var startTime = null;
                var endTime = null;
                $.each(result.accessPwdList, function (i, data) {
                    if (data.orderType) {
                        if (data.orderType == "1") {
                            orderType = "团课订单";
                        }
                        if (data.orderType == "4") {
                            orderType = "自助健身";
                        }
                        if (data.startTime) {
                            startTime = new Date(data.startTime).pattern("yyyy-MM-dd HH:mm");
                        }
                        if (data.endTime) {
                            endTime = new Date(data.endTime).pattern("yyyy-MM-dd HH:mm");
                        }
                    }


                    html += "<tr><td>" + data.userId + "</td>";
                    html += "<td>" + data.nickName + "</td>";
                    html += "<td>" + data.mobile + "</td>";
                    html += "<td>" + data.storeName + "</td>";
                    html += "<td>" + data.password + "</td>";
                    html += "<td>" + data.pwdUsedCount + "</td>";
                    html += "<td>" + data.orderNumber + "</td>";
                    html += "<td>" + orderType + "</td>";
                    html += "<td>" + startTime + "</td>";
                    html += "<td>" + endTime + "</td>";
                    html += "</tr>";
                });
                $("#access_pwd_list").html(html);

            }
        });
    }

    //点击教练门禁密码标签
    function coach_list(currentIndex) {
        debugger
        $("#c_access_pwd_list").empty();
        var relationId = $("#c_relationId").val().trim();
        var mobile = $("#c_mobile").val().trim();
        var storeId = $("#c_storeId").val().trim();

        $.ajax({
            url: "${baseUrl}system/accessPwd/access_pwd_list",
            data: {
                pageIndex: currentIndex,
                pageSize: 10,
                relationId: relationId,
                mobile: mobile,
                storeId: storeId,
                relationType: 1
            },
            type: "POST",
            success: function (result) {
                var html = "";
                //教练密码分页
                new Page({
                    parent: $("#coach-page"),
                    nowPage: currentIndex,
                    pageSize: 10,
                    totalCount: result.accessPwdCount,
                    setting: {
                        defaultPage: 5,//默认显示可点击分页的个数
                        firstPageText: "首页",
                        prevPageText: "上一页",
                        nextPageText: "下一页",
                        lastPageText: "尾页"
                    },
                    callback: function (nowPage, totalPage) {
                        coach_list(nowPage);
                    }
                });

                $("#coach_access_pwd_count").text(result.accessPwdCount);

                var startTime = null;
                var endTime = null;
                $.each(result.accessPwdList, function (i, data) {

                    if (data.startTime) {
                        startTime = new Date(data.startTime).pattern("yyyy-MM-dd HH:mm");
                    }
                    if (data.endTime) {
                        endTime = new Date(data.endTime).pattern("yyyy-MM-dd HH:mm");
                    }

                    html += "<tr><td>" + data.relationId + "</td>";
                    html += "<td>" + data.nickName + "</td>";
                    html += "<td>" + data.mobile + "</td>";
                    html += "<td>" + data.storeName + "</td>";
                    html += "<td>" + data.password + "</td>";
                    html += "<td>" + data.pwdUsedCount + "</td>";
                    html += "<td>" + startTime + "</td>";
                    html += "<td>" + endTime + "</td>";
                    html += "</tr>";
                });
                $("#c_access_pwd_list").html(html);
            }
        });
    }

    //点击系统用户门禁密码标签
    function system_user_list(currentIndex) {
        debugger
        $("#s_access_pwd_list").empty();
        var relationId = $("#s_relationId").val().trim();
        var mobile = $("#s_mobile").val().trim();
        var storeId = $("#s_storeId").val().trim();

        $.ajax({
            url: "${baseUrl}system/accessPwd/access_pwd_list",
            data: {
                pageIndex: currentIndex,
                pageSize: 10,
                relationId: relationId,
                mobile: mobile,
                storeId: storeId,
                relationType: 2
            },
            type: "POST",
            success: function (result) {
                var html = "";
                //教练密码分页
                new Page({
                    parent: $("#system-page"),
                    nowPage: currentIndex,
                    pageSize: 10,
                    totalCount: result.accessPwdCount,
                    setting: {
                        defaultPage: 5,//默认显示可点击分页的个数
                        firstPageText: "首页",
                        prevPageText: "上一页",
                        nextPageText: "下一页",
                        lastPageText: "尾页"
                    },
                    callback: function (nowPage, totalPage) {
                        coach_list(nowPage);
                    }
                });

                $("#system_access_pwd_count").text(result.accessPwdCount);

                var startTime = null;
                var endTime = null;
                $.each(result.accessPwdList, function (i, data) {

                    if (data.startTime) {
                        startTime = new Date(data.startTime).pattern("yyyy-MM-dd HH:mm");
                    }
                    if (data.endTime) {
                        endTime = new Date(data.endTime).pattern("yyyy-MM-dd HH:mm");
                    }

                    html += "<tr><td>" + data.relationId + "</td>";
                    html += "<td>" + data.nickName + "</td>";
                    html += "<td>" + data.mobile + "</td>";
                    html += "<td>" + data.storeName + "</td>";
                    html += "<td>" + data.password + "</td>";
                    html += "<td>" + data.pwdUsedCount + "</td>";
                    html += "<td>" + startTime + "</td>";
                    html += "<td>" + endTime + "</td>";
                    html += "</tr>";
                });
                $("#s_access_pwd_list").html(html);
            }
        });
    }



</script>

</@body.page>

</html>